require File.expand_path('../fluent_conditions/condition_builder.rb', __FILE__)
require File.expand_path('../fluent_conditions/accessor_definers.rb', __FILE__)

module FluentConditions

  def self.included(base)
    base.instance_variable_set(:@__builder, Class.new(ConditionBuilder))

    base.class_eval do
      include InstanceMethods
    end

    base.extend ClassMethods
  end

  module InstanceMethods
    def is
      self.class.instance_variable_get(:@__builder).new(self, :positive)
    end

    def is_not
      self.class.instance_variable_get(:@__builder).new(self, :negative)
    end
  end

  module ClassMethods
    def fluent(field, options = {})
      condition_builder = instance_variable_get(:@__builder)
      accessor_definer = AccessorDefinerFactory.make_for(condition_builder, options)
      accessor_definer.define(field)
    end
  end

end

